<template>
	<view style="background-color: #F7F7F9;">

		<view :class="item.platform== 1?'mt':'elm'"
			style="height: 200rpx;width: 750rpx;border-bottom-left-radius: 35rpx;border-bottom-right-radius: 35rpx;">
			<view class="flex j-b a-c f28 cff" style="padding-left: 50rpx;padding-right: 50rpx;padding-top: 25rpx;">
				<!-- 		<text>同城电话</text>
				<text>一键直连</text>
				<text>服务品质</text> -->
			</view>
		</view>
		<view class="p20   " style="margin-top: -120rpx;">
			<view class=" p20" style="background-color: #fff;border-radius: 35rpx;">
				<view class=" flex">
					<view class="" style="width: 150rpx;height: 150rpx;">
						<image style="height: 150rpx;width: 150rpx;" class="b_y" :src="business.pic"></image>
					</view>
					<view class="l50 ml2">
						<view class="flex j-b" style="width: 530rpx;font-weight: bold;">
							<text class="m_20 shop-list-name f34">{{business.name}}</text>
						</view>
						<view class="flex j-b pt1" style="width: 530rpx;margin-top: 20rpx;">
							<text class="f26 m_20 c7">{{business.fullAddress}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="hengxian" style="height: 10rpx;"></view>
		<view class="" style="position: -webkit-sticky; position: sticky;top: 0px;background-color: #fff;z-index: 10;">
			<view class="p20 flex a-c" style="background-color: #fff;">
				<view @click="ontab(0)" :class="tabIndex== 0? 'isxz' : 'iswxz'" class="ml20 ">
					<text class="f34">商家信息</text>
				</view>
			</view>
		</view>
		<view class="hengxian" style="height: 5rpx;"></view>
		<view style="background-color: #fff;">
			<view class="page bg-white b_y">
				<view style="margin: auto 40rpx;">
					<view class="f-d  bg-white p20 a-c bb" style="padding-top: 40rpx;padding-bottom: 40rpx;display: flex;">
						<view class="  c_pl" style="width: 180rpx;">
							<text class="f28 c_z">活动时间:</text>
						</view>
						<lb-picker v-if="!residue" @time="time" :list="cata_time" style="flex: 1;" :level="2"
							mode="unlinkedSelector" :value="daytime" :lei="1">
							<text class="f28 c_pl" style="color:#999;">{{daytime}}</text>
						</lb-picker>
						<text v-if="residue" class="f28 c_pl" style="color:#999;">{{daytime}}</text>
					</view>
					<view class="f-d bg-white p20 a-c bb" style="padding-top: 40rpx;padding-bottom: 40rpx;display: flex;">
						<view style="width: 180rpx;" class="  c_pl">
							<text class="f28 c_z">选择外卖平台:</text>
						</view>
						<view class="uni-list-cell-db">
							<lb-picker v-if="!residue" @cate="on_navcate" :list="nav_list" :level="2" mode="multiSelector"
								:value="nav_list" :lei="2">
								<text class="f28 c_pl" style="color:#999;">{{cata_name}}</text>
							</lb-picker>
							<text v-if="residue" class="f28 c_pl" style="color:#999;">{{cata_name}}</text>
						</view>
					</view>
					<view class="f-d  bg-white p20 a-c bb" style="padding-top: 40rpx;padding-bottom: 40rpx;">
						<view class="f28 c_pl" style="width: 180rpx;">
							<text class="f28 c_z">实付底限:</text>
						</view>
						<input :disabled="residue" class="f28 in" type="number" placeholder="请输入实付底限" v-model="item.paidin" />
					</view>
					<view class="f-d  bg-white p20 a-c bb" style="padding-top: 40rpx;padding-bottom: 40rpx;">
						<view class="f28 c_pl" style="width: 180rpx;">
							<text class="f28 c_z">佣金:</text>
						</view>
						<input :disabled="residue" class="f28 in" type="number"
							:placeholder="item.paidin?'佣金不能小于'+(ratio*item.paidin)+'元':'请输入佣金'" v-model="item.commission" />
					</view>
					<view class="f-d  bg-white p20 a-c bb" style="padding-top: 40rpx;padding-bottom: 40rpx;display: flex;">
						<view class="f28 c_pl" style="width: 180rpx;">
							<text class="f28 c_z">执行日期:</text>
						</view>
						<picker :disabled="residue" mode="date" @change="executionDates" :start="day"
							style="flex: 1;color:#999;">
							<view>{{item.execution}}</view>
						</picker>
					</view>
				</view>
			</view>
		</view>

		<view class="" style="height: 130rpx;"></view>
		<view class="dibu" style="height: 140rpx;" v-if="!residue">
			<view class="p10  flex ">
				<view class="flex j-s p10" style="width: 100%;display: flex;justify-content: space-between;">
					<view @click="on_tel(1)" class="flex a-c j-c b_y f800 f28 cff"
						style="flex: 1;margin-right: 20rpx; height: 100rpx;background-color: #0071FE;">
						<text>提交修改</text>
					</view>
					<view @click="on_tel(2)" class="flex a-c j-c b_y f800 f28 cff"
						style="flex: 1;height: 100rpx;background-color: #ff0000;">
						<text>删除</text>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>
<script>
	// import sete from '@/subPackages/common/yz-qr/yz-qr.vue';
	import {
		params
	} from '@/common/time_list.js';
	import LbPicker from '@/common/lb-picker';
	export default {
		components: {
			// sete,
			LbPicker
		},
		data() {
			return {
				residue: false,
				nav_list: ['美团', '饿了么'],
				cata_name: '请选择',
				cata_time: params,
				daytime: '请选择活动时间',
				item: {},
				business: {},
				day: '',
				tabIndex: 0,
				ratio: ''
			}
		},
		onShow() {
			this.ratio = uni.getStorageSync('publis').activityPercentage || '0.5'
			// 判断是否登录
			this.$module.ifToken(res => {
				if (res == 1) {
					this.$module.navigateTo('/pages/banmi/user_login')
				} else {
					this.$module.getNowFormatDates(res => {
						this.day = res
					})
					return
				}
			})
		},
		onLoad(options) {
			this.business = uni.getStorageSync('business')
			this.item = JSON.parse(options.item)
			if (this.item.residue >0) {
				this.residue = false
			} else {
				this.residue = true
			}
			this.daytime = JSON.parse(options.item).beginTime + '-' + JSON.parse(options.item).endTime
			this.cata_name = JSON.parse(options.item).platform == 1 ? '美团' : '饿了么'
			// this.formatDate(JSON.parse(options.item).executionDate)
		},

		methods: {
			formatDate(date) {
				var date = new Date(date);
				var YY = date.getFullYear() + '-';
				var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
				var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
				var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
				var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
				this.item.executionDate = YY + MM + DD
			},
			executionDates(e) {
				this.item.executionDate = e.detail.value
			},
			on_navcate(picker) {
				let index = picker.index[0]
				this.pickerIndex = picker.index[0]
				this.item.platform = picker.index[0] + 1
				this.cata_name = picker.item[0];
			},
			time(picker) {
				// this.daytime = picker.value.join("-"); //用来显示
				// this.item.beginTime = picker.value[0] //开始日期
				// this.item.endTime = picker.value[1] //结束日期

				let beginTime = picker.value[0]
				let endTime = picker.value[1]
				// console.log(beginTime.replace(':', ''), endTime.replace(':', ''))
				if (parseInt(endTime) < parseInt(beginTime)) {
					this.$module.showToast('开始时间不能大于结束时间')
					this.daytime = '请选择活动时间'
				} else if (parseInt(endTime) > parseInt(beginTime)) {
					this.daytime = picker.value.join("-"); //用来显示
					this.item.beginTime = picker.value[0] //开始日期
					this.item.endTime = picker.value[1] //结束日期
				}
			},
			on_tel(i) { //调用接口
				const that = this
				if (this.item.paidin < (this.item.commission * this.ratio)) {
					this.$module.showToast("佣金不能小于实付" + this.ratio * 100 + '%')
					return
				} else {
					let date = {
						data: ''
					}
					that.$module.sm(this.item, 1, res => {
						date.data = res
					})
					uni.showModal({
						title: '',
						content: i == 1 ? '是否确认修改' : '是否确认删除',
						confirmText: i == 1 ? '确认修改' : '确认删除',
						success: function(res) {
							if (res.confirm) {
								that.Htpp.post(i == 1 ? '/mehrb/meplus/activity/update' :
									'/mehrb/meplus/activity/delete',
									'app', {
										token: true,
										datalist: date
									}).then(ret => {
									that.$module.sm(ret, 2, res => {
										that.$module.switchTab('/pages/index/index')
									})
								})
							}
						}
					});
				}
			},


			ontab(index) {
				this.tabIndex = index;
			},

		},
		onNavigationBarButtonTap(e) {

		}
	}
</script>

<style scoped>
	.mt {
		background-color: #FDC400;
	}

	.elm {
		background-color: #0192FF;
	}

	.c_pl {
		margin-right: 20rpx;
	}

	.fk_img {
		margin-right: -10rpx;
	}

	.dibu {
		position: fixed;
		bottom: 0;
		background-color: #FFFFFF;
		height: 120rpx;
		width: 100%;
		border-top: solid 1rpx #f2f2f2;
	}

	.isxz {
		border-bottom: solid 8rpx #FFD821;
		height: 45rpx;
		font-weight: 800;
		padding-bottom: 50rpx;
	}

	.iswxz {
		padding-bottom: 50rpx;
		border-bottom: solid 8rpx #fff;
		height: 45rpx;
		color: #767676;
		font-weight: 800;
	}
</style>